package com.study.行为型模式.备忘录模式.实例2;

public class GameRole {

    private int attack;
    private int def;

    //创建Memento，即根据游戏角色当前的状态得到一个memento
    public Memento createMemento(){
        return new Memento(attack,def);
    }

    //从备忘录对象，恢复GameRole的状态
    public void recoverGameRoleFromMemento(Memento memento){
        this.attack = memento.getAttack();
        this.def = memento.getDef();
    }

    //显示当前游戏角色的状态
    public void display(){
        System.out.println("游戏角色当前的攻击力："+this.attack);
        System.out.println("游戏角色当前的防御力："+this.def);
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public void setDef(int def) {
        this.def = def;
    }
}
